<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
        .box {
            width: 200px;
            height: 200px;
            background: red;
        }
    </style>
</head>

<body>
    <div id="app">
        <ul>
            <li v-for="i in 10" @click="handler(i)">{{i}}</li>
        </ul>

        <button @click="toggle">toggle</button>
        <div class="box" v-show="flag"></div>
    </div>

    <script src="vue-2.4.0.js"></script>
    <script>
        let vm = new Vue({
            el: "#app", //代表vue作用的范围
            data: {
                flag: true,
            },
            methods: {
                handler(i) {
                    alert(i);
                },
                toggle() {
                    this.flag = !this.flag;
                    //在methods中如果使用 data记得加this
                },
            },
        });
    </script>
</body>

</html>